package demo.practice;

public class P50 {


    public static void main(String[] args) {
        P50 p50= new P50();
        double v = p50.myPow(2.00000, -2147483648);
        System.out.println(v);
    }

    public double myPow(double x, int n) {

        long b= n;
        if(b==0)
            return 1.0;

        boolean ne = b < 0; //负数


        double res = 0;
        b = Math.abs(b);
        if(b==1)
            res=x;


        if (b>1&&(b & 1) == 0) {
            double r1=myPow(x, (int)(b / 2));
            res=r1*r1;
        } else if(b>1) {
            res = myPow(x, (int)(b - 1)) * x;
        }

        if (ne)
            return 1 / res;

        return res;

        /*if(n==Integer.MIN_VALUE)
            return x*myPow(x,n-1);

        if (n == 0)
            return 1.0;


        double res = 0;

        boolean ne = n < 0; //负数
        n = Math.abs(n);
        if(n==1)
            res=x;


        if (n>1&&(n & 1) == 0) {
            double r1=myPow(x, n / 2);
            res=r1*r1;
        } else if(n>1) {
            res = myPow(x, n - 1) * x;
        }

        if (ne)
            return 1 / res;

        return res;*/
    }
}
